﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Red_Cross_Philippines;

namespace Philippine_National_Red_Cross
{
    
    public partial class frmUpdate : Form
    {
        string name, email, user, pass;
        int cur;
        public DataTable tbl = new DataTable();
       
        public frmUpdate(string name,string email,string user,string pass,int curIndex)
      
          
        {
            this.name = name;
            this.email = email;
            this.user = user;
            this.pass = pass;
            this.cur = curIndex;
            

            InitializeComponent();
            this.Load += new EventHandler(Form4_Load);
            btnEdit.Click += new EventHandler(btnEdit_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);
           
        }

        void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        void btnEdit_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "" || txtEmail.Text == "" || txtUsername.Text == "" || txtPassword.Text == "")
            {
                MessageBox.Show("Please check your inputs", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                return;
            }
            else if (txtConfirm.Text == "" )
            {
                MessageBox.Show("Please confirm your password", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                txtConfirm.Focus();
                return;
            }
            else if (txtConfirm.Text != txtPassword.Text)
            {
                MessageBox.Show("Password not match", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                txtConfirm.Clear();
                txtConfirm.Focus();
                return;
            }
            UpdateText();
        }


        private void UpdateText()
        {
            Blood_Bank_System BloodBank = new Blood_Bank_System();
            BloodBank.Connect();
            BloodBank.Query("SELECT * FROM tblusers");
            tbl = BloodBank.tbl;
            BloodBank.Disconnect();
            Account_Registration ar = new Account_Registration();

            ar.name = txtName.Text;
            ar.email = txtEmail.Text;
            ar.username = txtUsername.Text;
            ar.password = txtPassword.Text;

            if (rdClient.Checked == true)
            {
                ar.position = "Client";
            }
            else
            {
                ar.position = "Admin";
            }
            BloodBank.editAccount_Record(ar, cur);
            MessageBox.Show("You have successfully updated your account", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            this.Close();

        }

        void Form4_Load(object sender, EventArgs e)
        {
            txtName.Text = name;
            txtEmail.Text = email;
            txtUsername.Text = user;
            txtPassword.Text = pass;
        }
    }
}
